package com.demo.lcgl.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.demo.lcgl.controller.base.BaseController;
import com.demo.lcgl.entity.RegisteredUser;
import com.demo.lcgl.service.RegisteredUserService;

/**
 * 注册用户：(RegisteredUser)表控制层
 */
@RestController
@RequestMapping("/registered_user")
public class RegisteredUserController extends BaseController<RegisteredUser, RegisteredUserService> {

    /**
     * 注册用户对象
     */
    @Autowired
    public RegisteredUserController(RegisteredUserService service) {
        setService(service);
    }

    @PostMapping("/add")
    @Transactional
    public Map<String, Object> add(HttpServletRequest request) throws IOException {
        Map<String, Object> paramMap = service.readBody(request.getReader());
        Map<String, String> mapuser_number = new HashMap<>();
        mapuser_number.put("user_number", String.valueOf(paramMap.get("user_number")));
        List listuser_number = service.selectBaseList(service.select(mapuser_number, new HashMap<>()));
        if (listuser_number.size() > 0) {
            return error(30000, "字段用户编号内容不能重复");
        }
        this.addMap(paramMap);
        return success(1);
    }

}
